<template>
    <div class="container-content">
        <el-table
            v-loading="loading"
            ref="materialTable"
            :data="tableData"
            stripe
            border
            style="width: 100%"
            @selection-change="getSelectVal"
        >
            <!-- @selection-change="handleSelectionChange" -->
            <el-table-column type="selection" width="55" align="center">
            </el-table-column>
            <!-- <el-table-column prop="id" label="id"> </el-table-column> -->
            <el-table-column
                prop="materialName"
                label="物料名称"
            ></el-table-column>
            <el-table-column
                prop="materialCode"
                label="物料编码"
            ></el-table-column>
            <el-table-column prop="typeName" label="分类名称"></el-table-column>
            <el-table-column prop="unit" label="单位"></el-table-column>
            <el-table-column prop="model" label="规格型号"> </el-table-column>
            <el-table-column prop="paramDesc" label="参数说明">
            </el-table-column>
            <el-table-column prop="brand" label="品牌"></el-table-column>
            <el-table-column prop="type" label="物料类型">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.type == '1'">自购物料</el-tag>
                    <el-tag v-if="scope.row.type == '2'">甲购物料</el-tag>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
            class="pagination mt10"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            background
        >
        </el-pagination>
    </div>
</template>
<script>
import { getMaterialInfoList } from "@/api/system/warehouse";
export default {
    data() {
        return {
            tableData: [],
            currentPage: 1, //当前页
            pageSize: 10, //每页条数
            total: 0,
            loading: false,
        };
    },
    methods: {
        //分页器size
        handleSizeChange(val) {
            this.pageSize = val;
            this.getDataList();
        },
        //分页器当前页
        handleCurrentChange(val) {
            this.currentPage = val;
            this.getDataList();
        },
        getSelectVal(val) {
            // if (val.length) {
            this.$emit("update:visible", false);
            this.$emit("getSelectVal", val);
            // }
        },
        getDataList() {
            this.loading = true;
            getMaterialInfoList().then((res) => {
                this.tableData = res.data.records;
                this.total = res.data.total;
                this.loading = false;
            });
        },
    },
    mounted() {
        this.getDataList();
    },
};
</script>
<style lang="scss" scoped></style>
